package org.blogwu.learn.designpattern.chapter10.v2;


/**
 * 外部调用此类方法。此类作为方法流程的封装
 * 如果调用方法需要经常变动，可以加入一个接口，不同实现来完成不同的业务。
 *
 * @author hyf
 * @date 2018-10-25
 **/
public class GiftExchangeService {

    private QualifyService qualifyService = new QualifyService();

    private PointsPaymentService paymentService = new PointsPaymentService();

    private ShippingService shippingService = new ShippingService();

    public void setQualifyService(QualifyService qualifyService) {
        this.qualifyService = qualifyService;
    }

    public void setPaymentService(PointsPaymentService paymentService) {
        this.paymentService = paymentService;
    }

    public void setShippingService(ShippingService shippingService) {
        this.shippingService = shippingService;
    }

    public void giftExchange(PointGift pointGift) {
        // 封装购买礼物的操作
        if (qualifyService.isAvailable(pointGift)) {
            // 资格校验通过
            if (paymentService.pay(pointGift)) {
                // 积分扣减通过
                System.out.println("积分礼物购物成功，订单号：" + shippingService.shipGift(pointGift));
            }
        }
    }

}
